package com.platform.study.thread;

/**
 * 用实现Runnable接口方式实现线程:强制执行线程
 * User: wangyanginfo
 * Date: 12-11-26
 * Time: 下午2:44
 */
public class RunnableSimple_2 implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {
            System.out.println(Thread.currentThread().getName());
        }
    }

    public static void main(String[] args) {
        RunnableSimple_2 simpleA = new RunnableSimple_2();
        Thread thread = new Thread(simpleA, "线程1");
        //System.out.println("线程启动之前---》" + thread.isAlive());
        thread.start();
        //System.out.println("线程启动之后---》" + thread.isAlive());
        for (int i = 0; i < 50; i++) {
            if (i > 10) {
                try {
                    thread.join();  //强制执行thread
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            System.out.println("main 线程执行-->" + i);
        }

    }
}
